import os
import zipfile, logging
from pathlib import Path

from utils.result_send_util import inner_upload_file
log_path = os.path.join('logs')
reports_path = os.path.join('reports','allure-report')

def zip_logs_reports(output_zip: str, *paths: str):
    """
    将任意数量的文件/目录打包成 zip
    :param output_zip: 输出压缩包路径（可相对或绝对）
    :param paths: 可变参数，要打包的文件或目录
    :return: (绝对路径, 文件大小 bytes)
    """
    output_zip = Path(output_zip).resolve()          # 统一转成绝对路径
    with zipfile.ZipFile(output_zip, 'w', compression=zipfile.ZIP_DEFLATED) as zf:
        for path in paths:
            p = Path(path)
            if not p.exists():
                print(f'⚠️  {p} 不存在，已跳过')
                continue
            if p.is_file():
                zf.write(p, p.name)
            elif p.is_dir():
                for file in p.rglob('*'):
                    if file.is_file():
                        arcname = file.relative_to(p.parent)
                        zf.write(file, arcname)
    size = output_zip.stat().st_size
    print(f'✅ 压缩完成 -> {output_zip}  ({size} bytes)')
    return str(output_zip)     # 返回绝对路径和大小，方便后续调用


# ================= 调用示例 =================
# if __name__ == '__main__':
#     project_dir = r"C:\Users\王\Desktop\interface_automation_framework_longguopay"
#     zip_path = os.path.join(project_dir, "wzs.zip")
#     inner_upload_file('dingb6hwbnfe0uyyrjeb','ZJRlgVb77uh9MylP4ChTX9Xx364YvBwFk7gt_a8KSMkA1PWevcTnKJicButPDctf','chatd8559522173f92da4eb56f5fb9b3f6cc',zip_path)

